package it.asvp.asvp_portal.data.entity.news;

import it.asvp.asvp_portal.asvp_util.enumerative.NewsType;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.member.Member;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "news", catalog = "asvp_db")
public class News extends BaseEntity {

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "id_member", nullable = false)
  private Member           member;

  @Column(name = "news_type", nullable = false, length = 50)
  @Enumerated(EnumType.STRING)
  private NewsType         newsType;

  @Column(name = "title", nullable = false, length = 200)
  private String           title;

  @Column(name = "text", nullable = false, length = 1000)
  private String           text;

  @Column(name = "link", nullable = true, length = 255)
  private String           link;

  @Column(name = "priority", nullable = false)
  private boolean          priority;

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "news")
  @Cascade({ CascadeType.ALL })
  private Set<NewsPicture> newsPictures = new HashSet<NewsPicture>(0);

  public News() {
  }

  public News(Member member, NewsType newsType, String title, Date createdOn, String text, Date lastUpdate, String link, boolean priority) {
    this.member = member;
    this.newsType = newsType;
    this.title = title;
    this.text = text;
    this.link = link;
    this.priority = priority;
  }

  public Member getMember() {
    return this.member;
  }

  public void setMember(Member member) {
    this.member = member;
  }

  public NewsType getNewsType() {
    return this.newsType;
  }

  public void setNewsType(NewsType newsType) {
    this.newsType = newsType;
  }

  public String getTitle() {
    return this.title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getText() {
    return this.text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public String getLink() {
    return this.link;
  }

  public void setLink(String link) {
    this.link = link;
  }

  public Set<NewsPicture> getNewsPictures() {
    return this.newsPictures;
  }

  public void setNewsPictures(Set<NewsPicture> newsPictures) {
    this.newsPictures = newsPictures;
  }

  public boolean isPriority() {
    return priority;
  }

  public void setPriority(boolean priority) {
    this.priority = priority;
  }

}
